package com.redxiii.spike.pmi.commons;

import java.util.Date;

import com.redxiii.spike.api.pmi.entity.Issue;
import com.redxiii.spike.api.pmi.entity.IssuePriority;
import com.redxiii.spike.api.pmi.entity.IssueStatus;
import com.redxiii.spike.api.pmi.entity.IssueType;
import com.redxiii.spike.api.pmi.entity.Member;
import com.redxiii.spike.api.pmi.entity.Project;
import com.redxiii.spike.api.pmi.entity.ProjectCategory;
import com.redxiii.spike.api.pmi.entity.ProjectOutput;

/**
 * @author Daniel Filgueiras
 * @since 19/06/2011
 */
public abstract class DefaultIssue implements Issue {

	protected long id;
	protected Date createdDate;
	protected Date updatedOn;
	protected Date scheduleDate;
	protected Float percentageCompleted;
	protected Double spendTime;
	
	protected String summary;
	protected String rawDescription;
	protected String rawLastUpdate;
	
	protected Member author;
	protected Member assignedMember;
	protected Member memberLastUpdate;
	
	protected Project 			project;
	protected ProjectCategory	category;
	protected ProjectOutput		output;
	
	protected IssueStatus 		status;
	protected IssueType 		issueType;
	protected IssuePriority		priority;
	
	public DefaultIssue(long id, String summary) {
		this.id = id;
		this.summary = summary;
		this.createdDate = new Date();
	}
	

	@Override
	public int compareTo(Issue other) {
		if (this == other)
			return 0;
		
		return (int)(this.getId() - other.getId());
	}

	@Override
	public long getId() {
		return id;
	}

	@Override
	public Date getCreatedDate() {
		return createdDate;
	}

	@Override
	public Date getScheduleDate() {
		return scheduleDate;
	}

	@Override
	public Date getUpdatedOn() {
		return updatedOn;
	}

	@Override
	public Float getPercentageCompleted() {
		return percentageCompleted;
	}

	@Override
	public Double getSpendTime() {
		return spendTime;
	}
	
	@Override
	public String getSummary() {
		return summary;
	}

	@Override
	public String getRawDescription() {
		return rawDescription;
	}

	@Override
	public String getRawLastUpdate() {
		return rawLastUpdate;
	}

	@Override
	public Member getAuthor() {
		return author;
	}

	@Override
	public Member getAssignedMember() {
		return assignedMember;
	}

	@Override
	public Project getProject() {
		return project;
	}
	@Override
	public ProjectCategory getCategory() {
		return category;
	}
	@Override
	public ProjectOutput getOutput() {
		return output;
	}
	
	@Override
	public IssueStatus getStatus() {
		return status;
	}

	@Override
	public IssueType getType() {
		return issueType;
	}
	
	@Override
	public IssuePriority getPriority() {
		return priority;
	}

	public IssueType getIssueType() {
		return issueType;
	}

	public void setIssueType(IssueType issueType) {
		this.issueType = issueType;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public void setUpdatedOn(Date updatedOn) {
		this.updatedOn = updatedOn;
	}

	public void setScheduleDate(Date scheduleDate) {
		this.scheduleDate = scheduleDate;
	}

	public void setPercentageCompleted(Float percentageCompleted) {
		this.percentageCompleted = percentageCompleted;
	}
	
	public void setSpendTime(Double spendTime) {
		this.spendTime = spendTime;
	}
	
	public void setSummary(String summary) {
		this.summary = summary;
	}

	public void setRawDescription(String rawDescription) {
		this.rawDescription = rawDescription;
	}

	public void setRawLastUpdate(String rawLastUpdate) {
		this.rawLastUpdate = rawLastUpdate;
	}

	public void setAuthor(Member author) {
		this.author = author;
	}

	public void setAssignedMember(Member assignedMember) {
		this.assignedMember = assignedMember;
	}
	
	public Member getMemberLastUpdate() {
		return memberLastUpdate;
	}
	public void setMemberLastUpdate(Member memberLastUpdate) {
		this.memberLastUpdate = memberLastUpdate;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public void setCategory(ProjectCategory category) {
		this.category = category;
	}
	
	public void setOutput(ProjectOutput output) {
		this.output = output;
	}

	public void setStatus(IssueStatus status) {
		this.status = status;
	}

	public void setPriority(IssuePriority priority) {
		this.priority = priority;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((category == null) ? 0 : category.hashCode());
		result = prime * result + (int)id;
		result = prime * result + ((project == null) ? 0 : project.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DefaultIssue other = (DefaultIssue) obj;
		if (category == null) {
			if (other.category != null)
				return false;
		} else if (!category.equals(other.category))
			return false;
		if (id != other.id)
			return false;
		if (project == null) {
			if (other.project != null)
				return false;
		} else if (!project.equals(other.project))
			return false;
		return true;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("DefaultIssue [id=").append(id).append(", ");
		if (summary != null)
			builder.append("summary=").append(summary).append(", ");
		if (project != null)
			builder.append("project=").append(project).append(", ");
		if (category != null)
			builder.append("category=").append(category);
		builder.append("]");
		return builder.toString();
	}
	
	
	
}
